package itheima.zuoye.test1;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class ListUtils {
    //元素随机置换
    public static void shuffle(ArrayList<Integer>list){
       Collections.shuffle(list);

    }
    //获取元素最大值
    public static Integer getMax(ArrayList<Integer> list) {
        if (list == null || list.isEmpty()) {
            return null;
        }
        return Collections.max(list);
    }

    // 获取元素和
    public static Integer getSum(ArrayList<Integer> list) {
        if (list == null || list.isEmpty()) {
            return 0;
        }
        int sum = 0;
        for (Integer num : list) {
            sum += num;
        }
        return sum;
    }

    // 元素排序
    public static void sort(ArrayList<Integer> list) {
        Collections.sort(list);
    }

    // 元素填充
    public static void fill(ArrayList<Integer> list, Integer value) {
        Collections.fill(list, value);
    }

    // 元素反转
    public static void reverse(ArrayList<Integer> list) {
        Collections.reverse(list);
    }
}
